package club.justwill.single.persistence.jpo;

import club.justwill.single.persistence.support.ActivityBase;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by luoyu on 15-12-24.
 */
@Entity
@Table(name = "activity")
@NamedQueries({
        @NamedQuery(name = "Activity.getByUserId",
                query = "select act from Activity act where act.userId=:userId"),
        @NamedQuery(name = "Activity.getByActivityId",
                query = "select act from Activity act where act.activityId=:activityId"),
        @NamedQuery(name = "Activity.getByActivityIds",
                query = "select act from Activity act where act.activityId in (:activityIds)"),
        @NamedQuery(name = "Activity.searchActivity",
                query = "select act from Activity act ")
})
public class Activity extends ActivityBase {

    @Id
    @Column(name = "activity_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long activityId;

    //一个活动可以对应多个Userctivity 一对多 一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "activity")
    private Set<UserActivity> userActivitySet;

    public Set<UserActivity> getUserActivitySet() {
        if(userActivitySet == null){
            userActivitySet = new HashSet<UserActivity>();
        }
        return userActivitySet;
    }

    public void setUserActivitySet(Set<UserActivity> userActivitySet) {
        this.userActivitySet = userActivitySet;
    }

    public Long getActivityId() {
        return activityId;
    }

    public void setActivityId(Long activityId) {
        if(activityId == null) {
            this.activityId = 0L;
        } else {
            this.activityId = activityId;
        }
    }
}
